package com.poetize.plus.controller.ui;

import com.poetize.plus.entity.dto.FriendDTO;
import com.poetize.plus.entity.vo.FriendVO;
import com.poetize.plus.service.FriendService;
import com.poetize.plus.utils.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.security.PermitAll;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Insert;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author zuosy
 * @Date 2024/5/14 17:07
 **/
@Tag(name = "友链信息")
@RestController
@RequestMapping("/friend")
@RequiredArgsConstructor
public class FriendUiController {

    private final FriendService friendService;

    @PermitAll
    @GetMapping("/getFriends")
    @Operation(summary = "获取所有友链")
    public R<Map<String, List<FriendVO>>> getFriends(){
        return R.ok(friendService.getFriends());
    }

    @PostMapping("/add")
    @Operation(summary = "新增")
    @PreAuthorize(value = "hasAnyRole('common','administrator')")
    public R<Boolean> add(@RequestBody @Validated(Insert.class)FriendDTO friendDTO){
        return R.ok(friendService.add(friendDTO));
    }
}
